<script>
	var url;
	$(document).ready(function(){
	
		newData = function (){
			$('#dialog').dialog({
				title: 'Tambah Kontent Surat',
				width: 550,
				height: 600,
				closed: true,
				cache: false,
				href: base_url+'konten/add',
				modal: true
			});
			 
			$('#dialog').dialog('open');  
			url = base_url+'konten/save';
		}
		// end newData
		
		saveData = function(){
			$('#form1').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					//alert(result);
					var result = eval('('+result+')');
					if (result.success){
						$('#dialog').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');		// reload the user data
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.msg
						});
					}
				}
			});
		}
		//end saveData

		//edit data
		editData = function (value){
			//var row = $('#dg').datagrid('getSelected');	
			//if (row){
				$('#dialog').dialog({
					title: 'Edit Data Kontent',
					width: 550,
					height: 600,
					closed: true,
					cache: false,
					href: base_url+'konten/edit/'+value,
					modal: true
				});
				
				$('#dialog').dialog('open');  
				url = base_url+'konten/save/edit';
			//}
		}
		//end editData
		
		actionbutton = function(value, row, index){
			var col;
			//if (row.kd_fakultas != null) {
				col = '<a href="#" onclick="editData(\''+row.id_konten+'\');" class="easyui-linkbutton" iconCls="icon-edit">Setting Konten</a>';
			//}
			return col;
		}
		
		// load grid
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>konten/grid"});	
			//$('#dg').datagrid('enableFilter'); 			
		});	
		
		
		
		//# Tombol Bawah
		/*$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					{
						iconCls:'icon-add',
						text:'Tambah Data',
						handler:function(){
							newData();
						}
					}
				]
			});			
		});*/
		
	});
</script>

<table id="dg" title="" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar',
			">
	<thead>
		<tr>
			<!--<th field="tahun_penerimaan" sortable="true" width="80">Tahun Penerimaan</th> -->
			<th field="jenis_surat" sortable="true" width="100">Jenis Surat</th>
			<th field="nama_surat" sortable="true" width="100">Nama Surat</th>
			<th field="paragraf_1" sortable="true" width="150">Paragraf 1</th>
			<th field="paragraf_2" sortable="true" width="150">Paragraf 2</th>
			<th field="paragraf_3" sortable="true" width="150">Paragraf 3</th>
			<th field="paragraf_4" sortable="true" width="150">Paragraf 4</th>
			<th field="action" align="center" formatter="actionbutton" width="150">Aksi</th>
		</tr>
	</thead>
</table>
